//
//  SE_Find_VC.m
//  SkyEye
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 SE. All rights reserved.
//

#import "SE_Find_VC.h"
#import "UIViewController+RESideMenu.h"
#import "SENetTool.h"
#import "SE_Banner_Model.h"
#import "SE_View_Model.h"
#import "SE_Square_Model.h"
#import "SE_Find_View.h"

@interface SE_Find_VC ()

@property (nonatomic, retain) NSMutableArray *bannerArray;
@property (nonatomic, retain) NSMutableArray *viewArray;
@property (nonatomic, retain) NSMutableArray *squareArray;

@property (nonatomic, retain) SE_Find_View *findView;

@end

@implementation SE_Find_VC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.bannerArray = [NSMutableArray array];
    self.viewArray = [NSMutableArray array];
    self.squareArray = [NSMutableArray array];
    self.navigationItem.title = @"发现";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"left.jpg"] imageWithRenderingMode:1] style:UIBarButtonItemStylePlain target:self action:@selector(presentLeftMenuViewController:)];
    
    [self createFindView];
    
    [self handleData];
}


-(void)handleData
{
    NSString *urlStr = @"http://baobab.wandoujia.com/api/v3/discovery?_s=5d9da81d7ab97c7d570a5f8e7a74a71f&f=iphone&net=wifi&u=5b2b224c5b00b628366a35564c3ec03138d4cdfb&v=2.4.0&vc=1014";
    [SENetTool GET:urlStr body:nil headerFile:nil response:SEJSON success:^(id result) {

        NSArray *itemArray = [result objectForKey:@"itemList"];
        for (NSDictionary *itemDic in itemArray) {
            NSString *type = [itemDic objectForKey:@"type"];
            
            //广告
#pragma mark - horizontalScrollCard
            if ([type isEqualToString:@"horizontalScrollCard"]) {
                NSDictionary *dataDic = [itemDic objectForKey:@"data"];
                NSArray *itemList = [dataDic objectForKey:@"itemList"];
                for (NSDictionary *itemListDic in itemList) {
                    NSDictionary *newDataDic = [itemListDic objectForKey: @"data"];
                    [self.bannerArray addObject:[newDataDic objectForKey:@"image"]];
                    
                }
            }
            //方块
#pragma mark - squareCard
            if ([type isEqualToString:@"squareCard"]) {
                NSDictionary *dataDic = [itemDic objectForKey:@"data"];
                SE_Square_Model *model = [[SE_Square_Model alloc]initWithDic:dataDic];
                [self.squareArray addObject:model];
            }
            //360全景视频
#pragma mark - rectangleCard
            if ([type isEqualToString:@"rectangleCard"]) {
                NSDictionary *dataDic = [itemDic objectForKey:@"data"];
                SE_View_Model *model = [[SE_View_Model alloc]initWithDic:dataDic];
                [self.viewArray addObject:model];
            }
        }

        self.findView.bannerArray = self.bannerArray;
        self.findView.viewArray = self.viewArray;
        self.findView.squareArray = self.squareArray;
    } failure:^(NSError *error) {
        NSLog(@"%@", error);
    }];
}

-(void)createFindView{
    self.findView = [[SE_Find_View alloc]initWithFrame:self.view.frame];
    [self.view addSubview:self.findView];
}

@end












